package com.iocup.keybastion.spring.starter.config;

import com.ejlchina.okhttps.HTTP;
import com.ejlchina.okhttps.JacksonMsgConvertor;
import com.ejlchina.okhttps.OkHttps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * 配置okhttp的相关参数
 * @author xyjxust
 * @create 2022/4/18 10:04
 **/
@Configuration
public class HttpConfiguration {

    @Autowired
    private HttpProperties httpProperties;


    @Bean
    public HTTP http() {
        return OkHttps.newBuilder().config(builder -> {
            builder.connectTimeout(httpProperties.getConnectionDataHttpTimeout(), TimeUnit.SECONDS);
            builder.writeTimeout(httpProperties.getConnectionDataHttpTimeout(), TimeUnit.SECONDS);
            builder.callTimeout(httpProperties.getRequestDataHttpTimeout(), TimeUnit.SECONDS);
            builder.readTimeout(httpProperties.getRequestDataHttpTimeout(), TimeUnit.SECONDS);
        }).addMsgConvertor(new JacksonMsgConvertor()).build();
    }
}
